package xcmg.device.web.company;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.service.company.DealerLevelService;
import xcmg.device.service.vo.company.DealerLevelVO;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import java.util.List;

/**
 * Created by wrg on 2019/4/19.
 */
@RestController
@RequestMapping("/dealerLevel")
@Api("客户分级")
public class DealerLevelController extends BasicController {

    @Autowired
    private DealerLevelService dealerLevelService;

    @PostMapping(value = "/insert")
    @FastMappingInfo(needLogin = true)
    @ApiOperation(value = "新增客户分级")
    public ActionResult insert(@RequestBody DealerLevelVO dealerLevelVO)throws Exception{
        return actionResult(dealerLevelService.insert(dealerLevelVO,getUserId(),getOrgId()));
    }

    @PostMapping(value = "/update")
    @FastMappingInfo(needLogin = true)
    @ApiOperation(value = "修改客户分级")
    public ActionResult update(@RequestBody DealerLevelVO dealerLevelVO){
        if(StringUtils.isBlank(dealerLevelVO.getId())){
            return actionResult(ErrorCode.IllegalArument);
        }
        return actionResult(dealerLevelService.update(dealerLevelVO,getUserId()));
    }

    @GetMapping(value = "/remove")
    @FastMappingInfo(needLogin = true)
    @ApiOperation(value = "删除客户分级")
    public ActionResult delete(@RequestParam(value = "id") String id){
        if(StringUtils.isBlank(id)){
            return actionResult(ErrorCode.IllegalArument);
        }
        return actionResult(dealerLevelService.delete(id,getUserId()));
    }

    @PostMapping(value = "/list")
    @FastMappingInfo(needLogin = true)
    @ApiOperation(value = "获取客户分级列表")
    public ActionResult list() throws Exception{
        List<DealerLevelVO> dealerLevelVOList = dealerLevelService.list(getOrgId());
        return actionValueResult(dealerLevelVOList);
    }

    @GetMapping(value = "/detail")
    @FastMappingInfo(needLogin = true)
    @ApiOperation(value = "获取详情")
    public ActionResult detail(@RequestParam(value = "id")  String id){
        if(StringUtils.isBlank(id)){
            return actionResult(ErrorCode.IllegalArument);
        }
        return actionValueResult(dealerLevelService.getDetail(id));
    }

}
